//
//	File Name   :	PlatformWin32.cpp
//	Description :	PlatformWin32 implementation file.
//	Author		:	William McVicar
//  Mail		:	mcvicar.william@gmail.com
//

//  Precompiled Header
#include "CommonDefines.h"

//  Library Includes

//  Local Includes
#include "Clock.h"

//  This includes
#include "PlatformWin32.h"

//	Macros

//  Static Variables

//  Static Function Prototypes

//  Implementation

namespace Protein
{

PlatformWin32::PlatformWin32()
{
	//
}

PlatformWin32::~PlatformWin32()
{
	UnregisterClass( L"Protein Application", m_hInstance );
}

bool PlatformWin32::Initialise()
{
  m_hInstance = GetModuleHandle(NULL);
  WNDCLASSEX wc;

  SetThreadAffinityMask( GetCurrentThread(), 1 );

  memset(&wc, 0, sizeof(WNDCLASSEX));

  wc.cbSize		      = sizeof(WNDCLASSEX);
  wc.style		      = CS_HREDRAW | CS_VREDRAW;
  wc.lpfnWndProc	  = (WNDPROC)StaticWindowProc;
  wc.hInstance	    = m_hInstance;
  wc.hCursor		    = LoadCursor(NULL, IDC_ARROW);
  wc.hbrBackground  = (HBRUSH)COLOR_WINDOW;
  wc.lpszClassName  = L"Protein Application";

  RegisterClassEx(&wc);

  m_hWnd = CreateWindowEx(NULL,
                          L"Protein Application",   
                          L"Protein Application",
                          WS_OVERLAPPEDWINDOW,
                          300,
                          300,    
                          640,    
                          480,    
                          NULL,    
                          NULL,    
                          m_hInstance,    
                          NULL);
	return true;
}

LRESULT PlatformWin32::StaticWindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT ps;
	HDC hdc;

  switch(message)
  {
		case WM_PAINT:
			hdc = BeginPaint( hWnd, &ps );
			EndPaint( hWnd, &ps );
		return 0;

    case WM_DESTROY:
      PostQuitMessage(0);
    return 0;
  }

  return DefWindowProc( hWnd, message, wParam, lParam );
}

}